// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Bootstrapper.cs" company="http://buginbox.wordpress.com/">
//   Copyright (c) GNU General Public License version 2 (GPLv2)
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.ComponentModel.Composition.Hosting;
using System.Windows;
using Microsoft.Practices.Prism.MefExtensions;
using Microsoft.Practices.Prism.Regions;
using Module.Main;
using Module.Splash;
using Wpf.Core.Behavior;

namespace WpfPrismWithSplash
{
    /// <summary>
    /// The bootstrapper.
    /// </summary>
    internal class Bootstrapper : MefBootstrapper
    {
        /// <summary>
        /// The create shell.
        /// </summary>
        /// <returns>
        /// The shell of the application. 
        /// </returns>
        protected override DependencyObject CreateShell()
        {
            return Container.GetExportedValue<Shell>();
        }

        /// <summary>
        /// The initialize shell.
        /// </summary>
        protected override void InitializeShell()
        {
            base.InitializeShell();

            Application.Current.MainWindow = (Window)Shell;

            //// Application.Current.MainWindow.Show(); // The Show() method is called by the Splash Screen
        }

        /// <summary>
        /// Configures the <see cref="T:Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory"/> . This will be the list of default behaviors that will be added to a region.
        /// </summary>
        /// <returns>
        /// The Microsoft.Practices.Prism.Regions.IRegionBehaviorFactory.
        /// </returns>
        protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
        {
            var factory = base.ConfigureDefaultRegionBehaviors();

            factory.AddIfMissing("AutoPopulateExportedViewsBehavior", typeof(AutoPopulateExportedViewsBehavior));

            return factory;
        }

        /// <summary>
        /// Configures the <see cref="P:Microsoft.Practices.Prism.MefExtensions.MefBootstrapper.AggregateCatalog"/> used by MEF.
        /// </summary>
        protected override void ConfigureAggregateCatalog()
        {
            base.ConfigureAggregateCatalog();

            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));
            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(ViewExportAttribute).Assembly));
            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(SplashModule).Assembly));
            AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(MainModule).Assembly));
        }
    }
}